//
//  CatchViewController.m
//  MM
//
//  Created by 王晨辉 on 15/5/14.
//  Copyright (c) 2015年 王晨辉. All rights reserved.
//

#import "CatchViewController.h"
#import "TestQuestionsViewController.h"
@interface CatchViewController ()

@end

@implementation CatchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
   
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *ID = [user objectForKey:@"ID"];

    ////NSLog(@"%@",[BabyManager shareInstance].babyId);
    
    NSDictionary *param2 = @{@"userId": ID,@"babyId": [BabyManager shareInstance].babyId,@"typeId": self.typeID};
    [UserDAL startEvaluationParams:param2 withBlock:^(NSDictionary *data, NSError *error) {
        
        if (data) {
            
            
            ////NSLog(@"%@",data);

            
            NSArray *myArray = data[@"dataList"];

                
        if (myArray.count!=0) {
                    
                    
            ////NSLog(@"11111");

            //            ////NSLog(@"data的数据为%@",data);
            _muArrau = [NSMutableArray array];
            _muArray = [NSMutableArray array];
            _muarrIma = [NSMutableArray array];

            for (NSDictionary*myDic in myArray) {
                [_muArrau addObject:myDic[@"situationName"]];
                [_muArray addObject:myDic[@"situationId"]];
//                NSString * str = [myDic objectForKey:@""];
                
                [_muarrIma addObject:myDic[@"imageUrl"]];

                

                
            }
            
                    
                    
                    
        }else{
            
            alert(@"暂无信息返回");
            ////NSLog(@"2222");

            
        }

        [_tableView reloadData];
            
        }else
        {
            
            
        }
        
        
    }];
    
    //设置导航栏头文字
    self.navigationItem.title = @"感觉统合观察";
    //设置导航栏背景颜色
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#44afd7" alpha:1]];
    //设置导航栏字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];

    
    self.view.backgroundColor = [UIColor whiteColor];
    
    
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.rowHeight = 52;
    _tableView.tableFooterView=[[UIView alloc]init];
    _tableView.separatorStyle = UITableViewCellEditingStyleNone;
    [self.view addSubview:_tableView];
    
    
    //自定义左右按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"_0000_返回.png"]
                      forState:UIControlStateNormal];
    [button addTarget:self action:@selector(turntolast)
     forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 20, 15);
    
    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    self.navigationItem.leftBarButtonItem = menuButton;
    
    _muArray = [[NSMutableArray alloc]init];

    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    


    // Do any additional setup after loading the view from its nib.
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

{
    NSString *msg = [[NSString alloc] initWithFormat:@"您点击的是第%d个按钮!",buttonIndex];
    ////NSLog(@"msg:%@",msg);
    if (buttonIndex == 0) {
        
        [self dismissViewControllerAnimated:YES completion:nil];
        ////NSLog(@"1111111");
        
    }else if(buttonIndex == 1){
        
        
        ////NSLog(@"2222222");
        
        
    }
    
    
}

-(void)postDD:(NSMutableArray *)muArr{
    
    
    _muArray = muArr;
    
    
}

-(void)turntolast{
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark--- tableViewDelegate 每个区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _muArrau.count;
}

#pragma mark--- tableViewDelegate 区尾的高度

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0;
    
}
#pragma mark--- tableViewDelegate cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    static NSString *NOTIFY = @"cell";
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:NOTIFY];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NOTIFY];
        
        
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        
        //
        NSArray * imageName = [[NSArray alloc]initWithObjects:@"本体感测评@2x.png.png",@"触感测评@2x.png.png",@"平衡杆测评@2x.png.png",@"前庭觉测评@2x.png.png",@"视知觉测评@2x.png.png",@"知听觉测评@2x.png.png",@"知听觉测评@2x.png.png", nil];
        
        UILabel *nameLable = [[UILabel alloc]initWithFrame:CGRectMake(10+40+20, 0, 200, 52)];
        nameLable.text=[NSString stringWithFormat:@"%@",_muArrau[indexPath.row]];
        nameLable.textAlignment = NSTextAlignmentLeft;
        nameLable.font = [UIFont systemFontOfSize:18];
        ////NSLog(@"%@3123213213213213123213",_muArrau[indexPath.row]);
        [cell addSubview:nameLable];
        
        _image = [[UIImageView alloc]initWithFrame:CGRectMake(10, 6, 40, 40)];
        [_image sd_setImageWithURL:[NSURL  URLWithString:_muarrIma[indexPath.row]] placeholderImage:nil];

        
        
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, _tableView.rowHeight-1, SCREEN_WIDTH, 1)];
        view.backgroundColor = UIColorWithRGBA(229, 229, 231, 1);
        [cell addSubview:view];
        [cell addSubview:_image];
        
    }
    
    
    return cell;
    
    
    
}
#pragma mark--- tableViewDelegate 有几个区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
    
}
#pragma mark--- tableViewDelegat 点击方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    ////NSLog(@"%@",_muArray[indexPath.row]);
    
    TestQuestionsViewController * testVC = [[TestQuestionsViewController alloc]init];
    testVC.typeID = self.typeID;
    testVC.situationID =_muArray[indexPath.row];
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:testVC];
    [self presentViewController:nav animated:YES completion:nil];
    
    
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
